import {
  Controller,
  Get,
  Post,
  Body,
  Param,
  Delete,
  Put,
  Query,
} from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';

import { FoodService } from './food.service';
import {
  CreateFoodReqDto,
  FoodListReqDto,
  UpdateFoodDto,
} from './dto/food.dto';

@ApiTags('小程序/食物')
@Controller('app/food')
export class FoodController {
  constructor(private readonly foodService: FoodService) {}
  /**
   * 食物列表
   */
  @Post()
  foodList(@Body() params: FoodListReqDto) {
    return this.foodService.findAll(params);
  }

  /**
   * 食物详情
   */
  @Get(':foodId')
  foodDetail(@Param('foodId') foodId: number) {
    return this.foodService.findOne(foodId);
  }
}

@ApiTags('后台/食物')
@Controller('admin/food')
export class AdminFoodController {
  constructor(private readonly foodService: FoodService) {}
  /**
   * 食物新增
   */
  @Post()
  createFood(@Body() createFoodDto: CreateFoodReqDto) {
    return this.foodService.create(createFoodDto);
  }
  /**
   * 食物列表
   */
  @Get()
  foodList(@Query() params: FoodListReqDto) {
    return this.foodService.findPage(params);
  }

  /**
   * 食物详情
   */
  @Get(':foodId')
  foodDetail(@Param('foodId') foodId: number) {
    return this.foodService.findOne(foodId);
  }

  /**
   * 食物修改
   */
  @Put(':foodId')
  update(
    @Param('foodId') foodId: string,
    @Body() updateFoodDto: UpdateFoodDto,
  ) {
    this.foodService.update(foodId, updateFoodDto);
  }

  /**
   * 食物删除
   */
  @Delete(':foodId')
  async removeFood(@Param('foodId') foodId: number) {
    await this.foodService.fakeRemove(foodId);
  }
}
